//This do file can be used to merge the 2020 and 2016 datasets and conduct the analysis found in the paper and supplemental appendix. 

// Set the working directory to the script's directory
cd "/your/filepath/here/"
 
*read in and merge the two years of data files
append using "2016ANESforMerge.dta" "2020ANESforMerge.dta"

//White Identity
*Importance to identity 
generate white1 = 0 if wid1 == 5
replace white1 = 1/12 if wid1 == 4
replace white1 = 2/12 if wid1 == 3
replace white1 = 3/12 if wid1 == 2
replace white1 = 4/12 if wid1 == 1

*Whites work together 
generate white2 = 0 if wid2 == 5
replace white2 = 1/12 if wid2 == 4
replace white2 = 2/12 if wid2 == 3
replace white2 = 3/12 if wid2 == 2
replace white2 = 4/12 if wid2 == 1

*Whites not getting jobs
generate white3 = 0 if wid3 == 5
replace white3 = 1/12 if wid3 == 4
replace white3 = 2/12 if wid3 == 3
replace white3 = 3/12 if wid3 == 2
replace white3 = 4/12 if wid3 == 1

//Creation of white identity index
gen whiteindex = white1 + white2 + white3
tab whiteindex

gen highwhite = .
replace highwhite = 1 if whiteindex >= .75 & whiteindex <=1
replace highwhite = 0 if whiteindex <= .25 & whiteindex >=0
tab highwhite

label define highwhitel 0 "Low White Identity" 1 "High White Identity" 
label values highwhite highwhitel

tab highwhite

*****************************

//Ideology
generate ideo7 = 1 if ideology == 1
replace ideo7 = 2 if ideology == 2
replace ideo7 = 3 if ideology == 3
replace ideo7 = 4 if ideology == 4
replace ideo7 = 5 if ideology == 5
replace ideo7 = 6 if ideology == 6
replace ideo7 = 7 if ideology == 7

tab ideo7

label define ideo7l 1 "Extremely liberal" 2 "Liberal" 3 "Slightly liberal" 4 "Moderate; middle of the road" 5 "Slightly conservative" 6 "Conservative" 7 "Extremely conservative"
label values ideo7 ideo7l

tab ideo7

generate conservative = 0 if ideo7 == 1 | ideo7 == 2 | ideo7 == 3
replace conservative = 1 if ideo7 == 5 | ideo7 == 6 | ideo7 == 7

tab conservative

label define conservative1 0 "Liberal" 1 "Conservative" 
label values conservative conservative1

tab conservative

*****************************

//Party
tab pid7
drop if pid7 == -9
drop if pid7 == -8
tab pid7

gen pid3 = -1 if pid7 > 4
replace pid3 = 0 if pid7 == 4
replace pid3 = 1 if pid7 < 4

label define pid3l -1 "Republican" 0 "Independent" 1 "Democrat"
label values pid3 pid3l

tab pid3

gen republican = .
replace republican = 1 if pid7 > 4
replace republican = 0 if pid7 < 4 

label define republicanl 1 "Republican" 0 "Democrat"
label values republican republicanl

tab republican

gen democrat = .
replace democrat = 1 if pid7 < 4
replace democrat = 0 if pid7 > 4 

label define democratl 1 "Democrat" 0 "Republican"
label values democrat democratl

tab democrat

generate pstrength = 2 if pid7 == 1 | pid7 ==7
replace pstrength = 1 if pid7 ==2 | pid7 ==6
replace pstrength = 0 if pid7 ==3 | pid7 ==5
tab pstrength

label define pstrengthl 2 "Strong" 1 "Not very strong" 0 "Indepdent member of party"
label values pstrength pstrengthl

tab pstrength 

*****************************

//Demographics
tab age
drop if age == -2
tab age

label define agel 1 "1. 18-20" 2 "2. 21-24" 3 "3. 25-29" 4 "4. 30-34" 5 "5. 35-39" 6 "6. 40-44" 7 "7. 45-49" 8 "8. 50-54" 9 "9. 55-59" 10 "10. 60-64" 11 "11. 65-69" 12 "12. 70-74" 13 "13. 75+" 
label values age agel

tab gender
drop if gender == -9
drop if gender == 3
tab gender

tab race
drop if race == -9
drop if race == -8
drop if race == -2
tab race

generate minority = 1 if race !=1
replace minority = 0 if race ==1
tab minority

generate incomenew = .
replace incomenew = 1 if income ==1
replace incomenew = 2 if income ==2
replace incomenew = 3 if income ==3
replace incomenew = 4 if income ==4
replace incomenew = 5 if income ==5
replace incomenew = 6 if income ==6
replace incomenew = 7 if income ==7
replace incomenew = 8 if income ==8
replace incomenew = 9 if income ==9
replace incomenew = 10 if income ==10
replace incomenew = 11 if income ==11
replace incomenew = 12 if income ==12
replace incomenew = 13 if income ==13
replace incomenew = 14 if income ==14
replace incomenew = 15 if income ==15
replace incomenew = 16 if income ==16
replace incomenew = 17 if income ==17
replace incomenew = 18 if income ==18
replace incomenew = 19 if income ==19
replace incomenew = 20 if income ==20
replace incomenew = 21 if income ==21
replace incomenew = 22 if income ==22

label define incomenewl 1 "1. Under $9,999" 2 "2. $10,000-14,999" 3 "3. $15,000-19,999" 4 "4. $20,000-24,999" 5 "5. $25,000-29,999" 6 "6. $30,000-34,999" 7 "7. $35,000-39,999" 8 "8. $40,000-44,999" 9 "9. $45,000-49,999" 10 "10. $50,000-59,999" 11 "11. $60,000-64,999" 12 "12. 65,000-69,999" 13 "13. $70,000-74,999" 14 "14. $75,000-79,999" 15 "15. $80,000-89,999" 16 "16. $90,000-99,999" 17 "17. $100,000-109,999" 18 "18. $110,000-124,999" 19 "19. $125,000-149,999" 20 "20. $150,000-174,999" 21 "21. $175,000-249,999" 22 "22. 250,000 or more"
label values incomenew incomenewl

generate lnincome = ln(incomenew)

generate education = .
replace education = 1 if edu ==1
replace education = 2 if edu ==2
replace education = 3 if edu ==3
replace education = 4 if edu ==4
replace education = 5 if edu ==5

label define education1 1 "Less than high school" 2 "High school" 3 "Some post-high school" 4 "Bachelor's degree" 5 "Graduate degree"
label values education education1

tab education

*****************************

//INDEXES

*nationalism index 
generate nation1 = 1 if nationalism1 ==1
replace nation1 = .5 if nationalism1 ==2
replace nation1 = -.5 if nationalism1 ==3
replace nation1 = -1 if nationalism1 ==4

generate nation2 = 1 if nationalism2 ==1
replace nation2 = .5 if nationalism2 ==2
replace nation2 = -.5 if nationalism2 ==3
replace nation2 = -1 if nationalism2 ==4

generate nation3 = 1 if nationalism3 ==1
replace nation3 = .5 if nationalism3 ==2
replace nation3 = -.5 if nationalism3 ==3
replace nation3 = -1 if nationalism3 ==4

generate nation4= 1 if nationalism4 ==1
replace nation4 = .5 if nationalism4 ==2
replace nation4 = -.5 if nationalism4 ==3
replace nation4 = -1 if nationalism4 ==4

generate nationalindex = nation1 + nation2 + nation3 + nation4
tab nationalindex

generate nationindex = nationalindex/4

tab nationindex

*****************************

*racial resentment 

*Special favors
generate resent1 = -1 if rr1 == 5
replace resent1 = -.5 if rr1 == 4
replace resent1 = 0 if rr1 == 3
replace resent1 = .5 if rr1 == 2
replace resent1 = 1 if rr1 == 1

*Slavery
generate resent2 = -1 if rr2 == 1
replace resent2 = -.5 if rr2 == 2
replace resent2 = 0 if rr2 == 3
replace resent2 = .5 if rr2 == 4
replace resent2 = 1 if rr2 == 5

*Deserve more
generate resent3 = -1 if rr3 == 1
replace resent3 = -.5 if rr3 == 2
replace resent3 = 0 if rr3 == 3
replace resent3 = .5 if rr3 == 4
replace resent3 = 1 if rr3 == 5

*Try harder
generate resent4 = -1 if rr4 == 5
replace resent4 = -.5 if rr4 == 4
replace resent4 = 0 if rr4 == 3
replace resent4 = .5 if rr4 == 2
replace resent4 = 1 if rr4 == 1

gen resentindexes = resent1 + resent2 + resent3 + resent4

tab resentindexes

gen resentindex = resentindexes/4

tab resentindex

label define resentindexl -1 "Lowest Racial Resentment" 1 "Highest Racial Resentment" 
label values resentindex resentindexl

tab resentindex

*****************************

*immigration index
generate immig1 = 1 if immigration1 == 1
replace immig1 = .5 if immigration1 ==2
replace immig1 = -.5 if immigration1 ==3
replace immig1 = -1 if immigration1 ==4

generate immig2 = 1 if immigration2 == 1
replace immig2 = .5 if immigration2 ==2 | immigration2 ==3
replace immig2 = 0 if immigration2 ==4
replace immig2 = -.5 if immigration2 ==5 | immigration2 ==6
replace immig2 = -1 if immigration2 ==7

generate immig3 = 1 if immigration3 == 1
replace immig3 = .5 if immigration3 ==2 | immigration3 ==3
replace immig3 = -.5 if immigration3 ==4 | immigration3 ==5
replace immig3 = -1 if immigration3 ==6

generate immig4 = 1 if immigration4 == 1
replace immig4 = .5 if immigration4 ==2 | immigration4 ==3
replace immig4 = 0 if immigration4 ==4
replace immig4 = -.5 if immigration4 ==5 | immigration4 ==6
replace immig4 = -1 if immigration4 ==7

gen immigrantindex = immig1 + immig2 + immig3 + immig4

tab immigrantindex

gen immigrationindex = immigrantindex/4

tab immigrationindex

*****************************

*women index 
generate wom1 = 1 if women1 ==7
replace wom1 = .5 if women1 ==6 | women1 ==5
replace wom1 = 0 if women1 ==4
replace wom1 = -.5 if women1 ==3 | women1 ==2
replace wom1 = -1 if women1 ==1

generate wom2 = 1 if women2 ==1
replace wom2 = .5 if women2 ==2 | women2 ==3
replace wom2 = 0 if women2 ==4
replace wom2 = -.5 if women2 ==5 | women2 ==6
replace wom2 = -1 if women2 ==7

generate wom3 = 1 if women3 ==1
replace wom3 = .5 if women3 ==2 
replace wom3 = 0 if women3 ==3
replace wom3 = -.5 if women3 ==4
replace wom3 = -1 if women3 ==5

generate wom4 = 1 if women4 ==1
replace wom4 = .5 if women4 ==2 
replace wom4 = 0 if women4 ==3
replace wom4 = -.5 if women4 ==4 
replace wom4 = -1 if women4 ==5

generate windex = wom1 + wom2 + wom3 + wom4
tab windex

generate womenindex = windex/4
tab womenindex

*****************************

*climate index
generate clima1 = 1 if climate1 == 1
replace clima1 = .5 if climate1 ==2
replace clima1 = 0 if climate1 ==3
replace clima1 = -.5 if climate1 ==4
replace clima1 = -1 if climate1 ==5

generate clima2 = 1 if climate2 == 7
replace clima2 = .5 if climate2 ==6 | climate2 ==5
replace clima2 = 0 if climate2 ==4
replace clima2 = -.5 if climate2 ==3 | climate2 ==2
replace clima2 = -1 if climate2 ==1

generate cindex = clima1 + clima2 
tab cindex 

generate climateindex = cindex/2
tab climateindex

*****************************

*lgbtq+ index 
generate lgbt1 = 1 if lgbtq1 == 1 
replace lgbt1 = .5 if lgbtq1 ==2 | lgbtq1 ==3
replace lgbt1 = -.5 if lgbtq1 ==4 | lgbtq1 ==5
replace lgbt1 = -1 if lgbtq1 ==6 

generate lgbt2 = 1 if lgbtq2 == 1
replace lgbt2 = .5 if lgbtq2 ==2 | lgbtq2 ==3
replace lgbt2 = -.5 if lgbtq2 ==4 | lgbtq2 ==5
replace lgbt2 = -1 if lgbtq2 ==6

generate lgbt3 = 1 if lgbtq3 == 4
replace lgbt3 = .5 if lgbtq3 ==3
replace lgbt3 = -.5 if lgbtq3 ==2
replace lgbt3 = -1 if lgbtq3 ==1

generate lgbt4 = 1 if lgbtq4 ==2
replace lgbt4 = -1 if lgbtq4 ==1

generate lgbtqindexes = lgbt1 + lgbt2 + lgbt3 + lgbt4

tab lgbtqindexes

generate lgbtqindex = lgbtqindexes/4

tab lgbtqindex

*****************************

*medical insurance index
generate medinsurindex = 1 if medinsur == 7
replace medinsurindex = .5 if medinsur == 6 | medinsur ==5
replace medinsurindex = 0 if medinsur == 4
replace medinsurindex = -.5 if medinsur == 3 | medinsur ==2
replace medinsurindex = -1 if medinsur == 1

tab medinsurindex

*****************************

*abortion index
generate abortionindex = 1 if abortion == 1
replace abortionindex = .25 if abortion ==2
replace abortionindex = -.25 if abortion ==3
replace abortionindex = -1 if abortion ==4

tab abortionindex

*****************************

//OPERATIONAL IDEOLOGY

generate deathpen_test = -1 if deathpen == -1
replace deathpen_test = 0 if deathpen == 1

generate gunpurchase_test = -1 if gunpurchase == -1
replace gunpurchase_test = 0 if gunpurchase == 1 | gunpurchase == 0

generate welfarespend_test = -1 if welfarespend == -1
replace welfarespend_test = 0 if welfarespend == 1 | welfarespend == 0

generate milltax_test = -1 if milltax == -1
replace milltax_test = 0 if milltax == 1 | milltax == 0

generate treat2_test = -1 if treat2 == 1
replace treat2_test = 0 if treat2 == 2 | treat2 ==3

generate healthspend_test = -1 if healthspend == -1
replace healthspend_test = 0 if healthspend == 1 | healthspend == 0

generate operationideo_percent_test = ((deathpen_test + gunpurchase_test + welfarespend_test + milltax_test + healthspend_test + treat2_test)/6)

generate operational_ideology = 1 if operationideo_percent_test == -1
replace operational_ideology = 2 if operationideo_percent_test <= -.8 & operationideo_percent_test >= -.9
replace operational_ideology = 3 if operationideo_percent_test <= -.6 & operationideo_percent_test >= -.7
replace operational_ideology = 4 if operationideo_percent_test == -.5
replace operational_ideology = 5 if operationideo_percent_test <= -.3 & operationideo_percent_test >= -.4
replace operational_ideology = 6 if operationideo_percent_test <= -.1 & operationideo_percent_test >= -.2
replace operational_ideology = 7 if operationideo_percent_test == 0

*****************************

//TABLE A1 REGRESSION MODELS

regress nationindex republican whiteindex c.republican#c.whiteindex if race ==1

regress resentindex republican whiteindex c.republican#c.whiteindex if race ==1

regress immigrationindex republican whiteindex c.republican#c.whiteindex if race ==1

regress womenindex republican whiteindex c.republican#c.whiteindex if race ==1

regress climateindex republican whiteindex c.republican#c.whiteindex if race ==1

regress lgbtqindex republican whiteindex c.republican#c.whiteindex if race ==1

regress medinsurindex republican whiteindex c.republican#c.whiteindex if race ==1

regress abortionindex republican whiteindex c.republican#c.whiteindex if race ==1

*****************************

//TABLE A2 REGRESSION MODELS

regress nationindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress resentindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress immigrationindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress womenindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress climateindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress lgbtqindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress medinsurindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

regress abortionindex republican whiteindex c.republican#c.whiteindex age incomenew education gender ideo7 if race ==1

*****************************

//TABLE 1 ANALYSIS

tab republican
tab highwhite republican

*Median Age among Democrats
tab age
sum age if republican == 0, d //8 (See tab age)
sum age if republican == 0 & highwhite == 0, d //7 (See tab age)
sum age if republican == 0 & highwhite == 1, d //10 (See tab age)

*Median Age among Republicans
tab age
sum age if republican == 1, d //9 (See age table)
sum age if republican == 1 & highwhite == 0, d //8 (See tab age)
sum age if republican == 1 & highwhite == 1, d //10 (See tab age)

*Median Income among Democrats
tab incomenew
sum incomenew if republican == 0, d //11 (See tab incomenew)
sum incomenew if republican == 0 & highwhite == 0, d //15 (See tab incomenew)
sum incomenew if republican == 0 & highwhite == 1, d //8 (See tab incomenew)

*Income among Republicans
tab incomenew
sum incomenew if republican == 1, d //13 (See tab incomenew)
sum incomenew if republican == 1 & highwhite == 0, d //15 (See tab incomenew)
sum incomenew if republican == 1 & highwhite == 1, d //10 (See tab incomenew)

*Education among Democrats
tab education if republican == 0 //48.47%
tab education if republican == 0 & highwhite == 0 //64.04%
tab education if republican == 0 & highwhite == 1 //25.16%

*Education among Republicans
tab education if republican == 1 //40.05%
tab education if republican == 1 & highwhite == 0 //48.33%
tab education if republican == 1 & highwhite == 1 //27.82%

*Gender among Democrats
tab gender if republican == 0 //58.87%
tab gender if republican == 0 & highwhite == 0 //54.76%
tab gender if republican == 0 & highwhite == 1 //64.24%

*Gender among Republicans
tab gender if republican == 1 //48.46%
tab gender if republican == 1 & highwhite == 0 //39.00%
tab gender if republican == 1 & highwhite == 1 //58.33%

*Trump Thermometer among Democrats
sum thermtrump if republican == 0 & thermtrump >-1 //8.688
sum thermtrump if republican == 0 & highwhite == 0 & thermtrump >-1 //4.620
sum thermtrump if republican == 0 & highwhite == 1 & thermtrump >-1 //20.333

*Trump Thermometer among Republicans
sum thermtrump if republican == 1 & thermtrump >-1 //77.076
sum thermtrump if republican == 1 & highwhite == 0 & thermtrump >-1 //72.216
sum thermtrump if republican == 1 & highwhite == 1 & thermtrump >-1 //86.305

*GOP Thermometer among Democrats
sum thermrepparty if republican == 0 & thermrepparty >-1 & thermrepparty !=998 //19.423
sum thermrepparty if republican == 0 & highwhite == 0 & thermrepparty >-1 & thermrepparty !=998 //14.966
sum thermrepparty if republican == 0 & highwhite == 1 & thermrepparty >-1 //30.578

*GOP Thermometer among Republicans
sum thermrepparty if republican == 1 & thermrepparty >-1 & thermrepparty !=998 //71.973
sum thermrepparty if republican == 1 & highwhite == 0 & thermrepparty >-1 & thermrepparty !=998 //66.005
sum thermrepparty if republican == 1 & highwhite == 1 & thermrepparty >-1 & thermrepparty !=998 //81.266

*****************************


*Save the data file
save "MergedandCleanedDataset.dta", replace











































